package com.nmwlw.demo.ui

import android.app.ZysjSystemManager
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.getSystemService


@Preview
@Composable
fun CommonSetPreview() {
    CommonSetScreen()
//    WIFIScreen()
}

/**
 * 通用设置页面
 */
@Composable
fun CommonSetScreen() {
    Column (
        modifier = Modifier
            .fillMaxWidth()
            .height(IntrinsicSize.Min)
    ) {
        Row (
            verticalAlignment = Alignment.CenterVertically
        ){
            Text(
                text = "屏幕亮度调节",
                fontSize = 16.sp
            )
            Spacer(modifier = Modifier.weight(1f))
            OptionButton(
                name = "-",
                onClick = {})
            Spacer(modifier = Modifier.width(8.dp))
            OptionButton(
                name = "+",
                onClick = {})
        }
        Row (
            verticalAlignment = Alignment.CenterVertically
        ){
            Text(
                text = "WIFI设置",
                fontSize = 16.sp
            )
            Spacer(modifier = Modifier.weight(1f))
            OptionButton(
                modifier = Modifier,
                name = "前往",
                onClick = {})
        }
    }
}

@Composable
fun OptionButton(modifier: Modifier = Modifier,
                 name: String,
                 onClick: () -> Unit) {
    Button(
        modifier = modifier,
        shape = RoundedCornerShape(16.dp),
        colors = ButtonDefaults.buttonColors(
            containerColor = Color(0xFFFFA500)
        ),
        contentPadding = PaddingValues(12.dp),
        onClick = onClick
    ) {
        Text(text = name)
    }
}

@Composable
fun CustomSlider(sliderValue: Float,
                 onValueChange: (Float) -> Unit) {
    Column() {
        Slider(
            value = sliderValue,
            onValueChange = {},
            valueRange = 0f..100f, // 设置0-100范围
            steps = 99, // 允许100个整数值
            modifier = Modifier.padding(vertical = 8.dp),
            colors = SliderDefaults.colors(
                thumbColor = Color(0xFFFFA500), // 橙色滑块
                activeTrackColor = Color(0xFFFFA500), // 激活轨道颜色
                inactiveTrackColor = Color(0xFFFFA500).copy(alpha = 0.24f) // 未激活轨道颜色
            ),
        )
    }
}

/**
 * WIFI设置页面
 */
@Composable
fun WIFIScreen() {
    Column () {

    }
}
